/**
 * TODO <br>
 * 0.2: weijj:2019年5月10日 下午5:38:16:TODO <br>
 * @author  weijj
 * @since 2019年5月10日 下午5:38:16
 * @date 2019年5月10日 下午5:38:16
 * @version 0.1 初始为0.1,后续变更则修改
 */
package com.irdstudio.efp.batch.service.impl.dw;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import com.gdrcu.efp.cus.common.CusTypeEnum;
import com.irdstudio.basic.framework.core.constant.MonAlrmLvlEnums.MonAlrmLvlEnum;
import com.irdstudio.basic.framework.core.constant.SDicCertTypeEnum;
import com.irdstudio.basic.framework.core.util.DateTool;
import com.irdstudio.efp.batch.common.constant.BdLoanConstant;
import com.irdstudio.efp.batch.service.domain.TxtFileLoadBean;
import com.irdstudio.efp.batch.service.domain.dw.DwBaiduLoanBean;
import com.irdstudio.efp.batch.service.facade.dw.DwBaiduLoanBatchService;
import com.irdstudio.efp.batch.service.util.DueDataUtil;
import com.irdstudio.efp.batch.service.util.SDicMappingUtil;
import com.irdstudio.efp.batch.service.util.TxtFileLoadPlugin;
import com.irdstudio.efp.loan.common.LoanConstant;
import com.irdstudio.efp.loan.service.facade.AccLoanService;
import com.irdstudio.efp.loan.service.facade.AccoutErroTempService;
import com.irdstudio.efp.loan.service.facade.DwBaiduLoanTempService;
import com.irdstudio.efp.loan.service.vo.AccLoanVO;
import com.irdstudio.efp.loan.service.vo.AccoutErroTempVO;

/**
 * 根据百度同步过来的日初借据信息临时表数据修改借据表
 * 
 * @author weijj
 * @since 2019年5月10日 下午5:38:16
 * @version 1.0
 */
@Service("dwBaiduLoanBatchService")
public class DwBaiduLoanBatchServiceImpl implements DwBaiduLoanBatchService {

	private static Logger logger = LoggerFactory.getLogger(DwBaiduLoanBatchServiceImpl.class);

	@Autowired
	@Qualifier("accLoanService")
	private AccLoanService accLoanService;// 借据信息

	@Autowired
	@Qualifier("dwBaiduLoanTempService")
	private DwBaiduLoanTempService dwBaiduLoanTempService;// 日初借据信息临时信息

	@Autowired
	@Qualifier("accoutErroTempService")
	private AccoutErroTempService accoutErroTempService;// 错误信息

	// /**
	// * 根据百度同步过来的日初借据信息临时表数据修改借据表 <br>
	// * 0.1: weijj:2019年5月10日 下午5:40:11:新增 <br>
	// *
	// * @author weijj
	// * @since 2019年5月10日 下午5:40:11
	// * @date 2019年5月10日 下午5:40:11
	// * @version 0.1
	// */
	// @Override
	// public boolean batchUpdateDwBaiduLoan() throws Exception {
	// // TODO Auto-generated method stub
	//
	// boolean result = false;
	// long startTime = System.currentTimeMillis();
	// logger.info("同步过来的日初借据信息临时表数据修改借据表：[" + DateTool.formatDate(new
	// Date(startTime), DateTool.PATTERN_DATETIME) + "]， 处理开始");
	// // 可以配置参数
	// Integer pageSize = 1000;
	// try {
	// // 单位转换
	// final int oneHundred100 = 100;
	// // 需要新增或者修改的借据信息
	// List<AccLoanVO> list = null;
	// // 分页信息
	// DwBaiduLoanTempVO pageInfo = new DwBaiduLoanTempVO();
	// // 新增或者修改的借据信息
	// int num = 0;
	// // 页数
	// int page = 1;
	// // pageSize初始化
	// if (pageSize > 0) {
	// pageInfo.setSize(pageSize);
	// } else {
	// pageInfo.setSize(1000);
	// }
	// final String createUser = "admin";
	// // 判断循环次数
	// int size = dwBaiduLoanTempService.queryCount();
	// String size_msg = "【借据表】数据量：" + size;
	// logger.info(size_msg, "message{}");
	// int loopCount = (size / pageInfo.getSize()) + 1;
	// for (int i = 0; i < loopCount; i++) {
	// // 分页查询【借据表】数据
	// List<DwBaiduLoanTempVO> tempList =
	// dwBaiduLoanTempService.queryByPage(pageInfo);
	// list = new ArrayList<AccLoanVO>();
	// if (tempList != null && !tempList.isEmpty()) {
	// for (DwBaiduLoanTempVO dwBaiduLoanTempVO : tempList) {
	// // 借据表信息
	// AccLoanVO accLoanVO = new AccLoanVO();
	// accLoanVO.setBillNo(dwBaiduLoanTempVO.getLoanId());
	// // prd_id 产品ID
	// accLoanVO.setPrdId(SDicMappingUtil.getLocalSysDicVal(BdLoanConstant.PRD_CODE,
	// dwBaiduLoanTempVO.getProdtp()));
	// // prd_code 产品代码
	// accLoanVO.setPrdCode(SDicMappingUtil.getLocalSysDicVal(BdLoanConstant.PRD_CODE,
	// dwBaiduLoanTempVO.getProdtp()));
	// // prd_name 产品名称
	// accLoanVO.setPrdName(SDicMappingUtil.getLocalSysDicVal(BdLoanConstant.PRD_NAME,
	// dwBaiduLoanTempVO.getProdtp()));
	// accLoanVO.setCurType(SDicMappingUtil.getLocalSysDicVal(BdLoanConstant.CURRENCY,
	// dwBaiduLoanTempVO.getCurrency()));
	// accLoanVO.setLoanAmount(DueDataUtil.checkDecimalInfo(dwBaiduLoanTempVO.getEncashAmt(),
	// oneHundred100));
	// // prin_bal 正常本金余额
	// BigDecimal prinBal =
	// DueDataUtil.checkDecimalInfo(dwBaiduLoanTempVO.getPrinBal(),
	// oneHundred100);
	// // ovd_prin_bal 逾期本金余额
	// BigDecimal ovdPrinBal =
	// DueDataUtil.checkDecimalInfo(dwBaiduLoanTempVO.getOvdPrinBal(),
	// oneHundred100);
	// // loan_balance 借据余额 = prin_bal + ovd_prin_bal
	// BigDecimal loanBalance = prinBal.add(ovdPrinBal);
	// accLoanVO.setLoanBalance(loanBalance);
	// accLoanVO.setLoanStartDate(DueDataUtil.dateInfoTrans(dwBaiduLoanTempVO.getStartDate()));
	// accLoanVO.setLoanEndDate(DueDataUtil.dateInfoTrans(dwBaiduLoanTempVO.getEndDate()));
	// accLoanVO.setReceIntCumu(DueDataUtil.checkDecimalInfo(dwBaiduLoanTempVO.getIntTotal(),
	// oneHundred100));
	// accLoanVO.setActualIntCumu(DueDataUtil.checkDecimalInfo(dwBaiduLoanTempVO.getIntRepay(),
	// oneHundred100));
	// accLoanVO.setDelayIntCumu(DueDataUtil.checkDecimalInfo(dwBaiduLoanTempVO.getOvdIntBal(),
	// oneHundred100));
	// // 借据逾期
	// if (BdLoanConstant.LOAN_FORM_2.equals(dwBaiduLoanTempVO.getLoanForm())) {
	// // 拖欠本金有值，正常本金为0
	// // unpd_prin_bal decimal(16,2) Y 拖欠本金
	// accLoanVO.setUnpdPrinBal(loanBalance);
	// accLoanVO.setNormalBalance(BigDecimal.ZERO);
	// } else {
	// // 正常本金为有值，拖欠本金为0
	// accLoanVO.setUnpdPrinBal(BigDecimal.ZERO);
	// // normal_balance decimal(16,2) Y 正常贷款余额(元)
	// accLoanVO.setNormalBalance(loanBalance);
	// }
	// accLoanVO.setOverTimesCurrent(dwBaiduLoanTempVO.getCurOvdTerms());
	// accLoanVO.setOverTimesTotal(dwBaiduLoanTempVO.getTotalOvdTerms());
	// accLoanVO.setLatestRepayDate(DueDataUtil.dateInfoTrans(dwBaiduLoanTempVO.getLastRepayDate()));
	// accLoanVO.setSettlDate(DueDataUtil.dateInfoTrans(dwBaiduLoanTempVO.getClearDate()));
	// accLoanVO.setLastUpdateTime(DateTool.getCurrentDateTime());
	// if (BdLoanConstant.LOAN_FORM_2.equals(dwBaiduLoanTempVO.getLoanForm())) {
	// // 借据逾期
	// accLoanVO.setAccountStatus(LoanConstant.TZZT_YQ);
	// } else {
	// accLoanVO.setAccountStatus(
	// SDicMappingUtil.getLocalSysDicVal(BdLoanConstant.LOAN_STATUS,
	// dwBaiduLoanTempVO.getLoanStatus()));
	// }
	// //
	// accLoanVO.setPrinIntRateInc(DueDataUtil.checkDecimalInfo(dwBaiduLoanTempVO.getPnltIntTotal(),
	// // oneHundred100));
	// //
	// accLoanVO.setUnpdArrsIntBal(DueDataUtil.checkDecimalInfo(dwBaiduLoanTempVO.getPnltIntBal(),
	// // oneHundred100));
	// // unpd_arr_prn_bal decimal(16,2) Y 应收复利(应收未收) 赋值：0
	// accLoanVO.setUnpdArrPrnBal(BigDecimal.ZERO);
	// // act_arrs_int_bal decimal(16,2) Y 实收拖欠本金的罚息
	// accLoanVO.setActArrsIntBal(DueDataUtil.checkDecimalInfo(dwBaiduLoanTempVO.getPnltIntRepay(),
	// oneHundred100));
	// // act_arr_prn_bal decimal(16,2) Y 实收复利 赋值：0
	// accLoanVO.setActArrPrnBal(BigDecimal.ZERO);
	// accLoanVO.setReturnDate(dwBaiduLoanTempVO.getRepayDay().toString());
	// // unpd_arrs_int_bal1 decimal(16,2) Y 拖欠本金的罚息(应收未收)
	// accLoanVO.setUnpdArrsIntBal1(DueDataUtil.checkDecimalInfo(dwBaiduLoanTempVO.getPnltIntBal(),
	// oneHundred100));
	// // unpd_arr_prn_bal1 decimal(16,2) Y 应收复利(应收未收) 赋值：0
	// accLoanVO.setUnpdArrPrnBal1(BigDecimal.ZERO);
	// //
	// accLoanVO.setUnpdPrinBal(DueDataUtil.checkDecimalInfo(dwBaiduLoanTempVO.getOvdPrinBal(),
	// // oneHundred100));
	// accLoanVO.setIntAccr(DueDataUtil.checkDecimalInfo(dwBaiduLoanTempVO.getIntBal(),
	// oneHundred100));
	// accLoanVO.setDelayIntCumu1(DueDataUtil.checkDecimalInfo(dwBaiduLoanTempVO.getPnltIntTotal(),
	// oneHundred100));
	// accLoanVO.setPrdType(SDicMappingUtil.getLocalSysDicVal(BdLoanConstant.PRD_TYPE,
	// dwBaiduLoanTempVO.getProdtp()));
	// // assure_means_main char(2) Y 主担保方式 赋值：00-信用
	// accLoanVO.setAssureMeansMain(BdLoanConstant.ASSURE_MEANS_MAIN_00);
	// accLoanVO.setRepaymentMode(
	// SDicMappingUtil.getLocalSysDicVal(BdLoanConstant.REPAY_MODE,
	// dwBaiduLoanTempVO.getRepayMode()));
	// accLoanVO.setCusType(CusTypeEnum.NATURAL_MAN.getCode());
	// accLoanVO.setRepayFreq(dwBaiduLoanTempVO.getRepayCycle());
	// accLoanVO.setCreateUser(createUser);
	// accLoanVO.setCreateTime(formatDateTime10To19(dwBaiduLoanTempVO.getEtlDate()));
	// accLoanVO.setLastUpdateUser(createUser);
	// accLoanVO.setCertType(SDicCertTypeEnum.IDCARD.getValue());
	// accLoanVO.setLoanUseType(BdLoanConstant.LOAN_USE_TYPE_23);
	// accLoanVO.setIrAdjustMode(BdLoanConstant.IR_ADJUST_MODE_1);
	// accLoanVO.setChannelCode(BdLoanConstant.BD_CHANNEL_NO);
	// accLoanVO.setOverdueDays(dwBaiduLoanTempVO.getCurOvdDays());
	// accLoanVO.setCurrTerm(dwBaiduLoanTempVO.getCurTerm());
	// accLoanVO.setLoanTerm(dwBaiduLoanTempVO.getTotalTerms());
	// accLoanVO.setLoadTermType(BdLoanConstant.TERM_TYPE_M);
	// accLoanVO.setGraceDay(dwBaiduLoanTempVO.getGraceDay());
	// accLoanVO.setFundFeeTotal(DueDataUtil.checkDecimalInfo(dwBaiduLoanTempVO.getFundFeeTotal(),
	// oneHundred100));
	// accLoanVO.setFundFeeRepay(DueDataUtil.checkDecimalInfo(dwBaiduLoanTempVO.getFundFeeRepay(),
	// oneHundred100));
	// accLoanVO.setChargesTotal(DueDataUtil.checkDecimalInfo(dwBaiduLoanTempVO.getChargesTotal(),
	// oneHundred100));
	// accLoanVO.setChargesRepay(DueDataUtil.checkDecimalInfo(dwBaiduLoanTempVO.getChargesRepay(),
	// oneHundred100));
	// accLoanVO.setOverdueTotal(DueDataUtil.checkDecimalInfo(dwBaiduLoanTempVO.getOverdueTotal(),
	// oneHundred100));
	// accLoanVO.setOverdueRepay(DueDataUtil.checkDecimalInfo(dwBaiduLoanTempVO.getOverdueRepay(),
	// oneHundred100));
	// accLoanVO.setRepayViolateTotal(DueDataUtil.checkDecimalInfo(dwBaiduLoanTempVO.getRepayViolateTotal(),
	// oneHundred100));
	// accLoanVO.setRepayViolateRepay(DueDataUtil.checkDecimalInfo(dwBaiduLoanTempVO.getRepayViolateRepay(),
	// oneHundred100));
	// accLoanVO.setRefundViolateTotal(DueDataUtil.checkDecimalInfo(dwBaiduLoanTempVO.getRefundViolateTotal(),
	// oneHundred100));
	// accLoanVO.setRefundViolateRepay(DueDataUtil.checkDecimalInfo(dwBaiduLoanTempVO.getRefundViolateRepay(),
	// oneHundred100));
	// accLoanVO.setServiceTotal(DueDataUtil.checkDecimalInfo(dwBaiduLoanTempVO.getServiceTotal(),
	// oneHundred100));
	// accLoanVO.setServiceRepay(DueDataUtil.checkDecimalInfo(dwBaiduLoanTempVO.getServiceRepay(),
	// oneHundred100));
	// accLoanVO.setIntReducedAmCoupon(DueDataUtil.checkDecimalInfo(dwBaiduLoanTempVO.getIntReducedAmCoupon(),
	// oneHundred100));
	// accLoanVO.setPnltReducedAmtCoupon(DueDataUtil.checkDecimalInfo(dwBaiduLoanTempVO.getPnltReducedAmtCoupon(),
	// oneHundred100));
	// accLoanVO.setFundFeeReducedAmtCoupon(
	// DueDataUtil.checkDecimalInfo(dwBaiduLoanTempVO.getFundFeeReducedAmtCoupon(),
	// oneHundred100));
	// accLoanVO.setChargesReducedAmtCoupon(
	// DueDataUtil.checkDecimalInfo(dwBaiduLoanTempVO.getChargesReducedAmtCoupon(),
	// oneHundred100));
	// accLoanVO.setOverdueReducedAmtCoupon(
	// DueDataUtil.checkDecimalInfo(dwBaiduLoanTempVO.getOverdueReducedAmtCoupon(),
	// oneHundred100));
	// accLoanVO.setRepayViolateReducedAmtCoupon(
	// DueDataUtil.checkDecimalInfo(dwBaiduLoanTempVO.getRepayViolateReduAmtCoupon(),
	// oneHundred100));
	// accLoanVO.setRefundViolateReducedAmtCoupon(
	// DueDataUtil.checkDecimalInfo(dwBaiduLoanTempVO.getRefundViolateReduAmtCoupon(),
	// oneHundred100));
	// accLoanVO.setServiceReducedAmtCoupon(
	// DueDataUtil.checkDecimalInfo(dwBaiduLoanTempVO.getServiceReducedAmtCoupon(),
	// oneHundred100));
	// accLoanVO.setPrinReducedAmtManual(DueDataUtil.checkDecimalInfo(dwBaiduLoanTempVO.getPrinReducedAmtManual(),
	// oneHundred100));
	// accLoanVO.setIntReducedAmtManual(DueDataUtil.checkDecimalInfo(dwBaiduLoanTempVO.getIntReducedAmtManual(),
	// oneHundred100));
	// accLoanVO.setPnltReducedAmtManual(DueDataUtil.checkDecimalInfo(dwBaiduLoanTempVO.getPnltReducedAmtManual(),
	// oneHundred100));
	// accLoanVO.setFundFeeReducedAmtManual(
	// DueDataUtil.checkDecimalInfo(dwBaiduLoanTempVO.getFundFeeReducedAmtManual(),
	// oneHundred100));
	// accLoanVO.setChargesReducedAmtManual(
	// DueDataUtil.checkDecimalInfo(dwBaiduLoanTempVO.getChargesReducedAmtManual(),
	// oneHundred100));
	// accLoanVO.setOverdueReducedAmtManual(
	// DueDataUtil.checkDecimalInfo(dwBaiduLoanTempVO.getOverdueReducedAmtManual(),
	// oneHundred100));
	// accLoanVO.setRepayViolateReducedAmtManual(
	// DueDataUtil.checkDecimalInfo(dwBaiduLoanTempVO.getRepayViolateReduAmtManual(),
	// oneHundred100));
	// accLoanVO.setRefundViolateReducedAmtManual(
	// DueDataUtil.checkDecimalInfo(dwBaiduLoanTempVO.getRefundViolateReduAmtManual(),
	// oneHundred100));
	// accLoanVO.setServiceReducedAmtManual(
	// DueDataUtil.checkDecimalInfo(dwBaiduLoanTempVO.getServiceReducedAmtManual(),
	// oneHundred100));
	// list.add(accLoanVO);
	// }
	// // 需要新增或者更新的借据信息
	// if (list != null && !list.isEmpty()) {
	// int updateSize = accLoanService.insertOrUpdateAccLoan(list);
	// num += updateSize;
	// }
	// }
	// pageInfo.setPage(++page);
	// }
	// String num_msg = "【借据信息表】插入或更新数据处理结果:" + num;
	// logger.info(num_msg, "message{}");
	// result = true;
	// } catch (Exception e) {
	// e.printStackTrace();
	// String tableName = "acc_loan";
	// String errorMsg = "同步过来的日初借据信息临时表数据修改借据信息表出错";
	// String remark = "同步过来的日初借据信息临时表数据修改借据信息表出错，错误信息：" + e.getMessage();
	// addErrorInfo(tableName, MonAlrmLvlEnum.SERIOUS.getEnname(), errorMsg,
	// remark);
	// logger.error(remark);
	// throw new Exception(remark);
	// }
	// long endTime = System.currentTimeMillis();
	// logger.info("同步过来的日初借据信息临时表数据修改借据信息表出错：[" + DateTool.formatDate(new
	// Date(endTime), DateTool.PATTERN_DATETIME) + "]， 处理结束");
	// logger.info("SERIOUS，耗时：[" + (endTime - startTime) / 1000.0 + "]秒，处理结果[" +
	// result + "]");
	// return result;
	// }

	/**
	 * 根据百度同步过来的日初借据信息临时表数据修改借据表 <br>
	 * 0.1: weijj:2019年5月10日 下午5:40:11:新增 <br>
	 * 
	 * @author weijj
	 * @since 2019年5月10日 下午5:40:11
	 * @date 2019年5月10日 下午5:40:11
	 * @version 0.1
	 */
	@Override
	public boolean batchUpdateDwBaiduLoan(String fileUrl) throws Exception {
		// 处理结果
		boolean result = false;
		long startTime = System.currentTimeMillis();
		logger.info("同步过来的日初借据信息临时表数据修改借据表：[" + DateTool.formatDate(new Date(startTime), DateTool.PATTERN_DATETIME) + "]， 处理开始");
		try {
			TxtFileLoadPlugin txtFileLoadPlugin = new TxtFileLoadPlugin(fileUrl, "\u0002", "UTF-8", 0, 1000);
			List<TxtFileLoadBean> txtFileLoadList = txtFileLoadPlugin.run(new DwBaiduLoanBean());
			result = dueData(txtFileLoadList);
			if (txtFileLoadList.size() != 0) {
				while (!txtFileLoadList.get(txtFileLoadList.size() - 1).isReadedComplete) {
					txtFileLoadPlugin.setFirstRead(false);
					txtFileLoadList = txtFileLoadPlugin.run(new DwBaiduLoanBean());
					if (txtFileLoadList.size() == 0) {
						break;
					}
					result = dueData(txtFileLoadList);
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
			String tableName = "acc_loan";
			String errorMsg = "同步过来的日初借据信息临时表数据修改借据信息表出错";
			String remark = "同步过来的日初借据信息临时表数据修改借据信息表出错，错误信息：" + e.getMessage();
			addErrorInfo(tableName, MonAlrmLvlEnum.SERIOUS.getEnname(), errorMsg, remark);
			logger.error(remark);
			throw new Exception(remark);
		}
		long endTime = System.currentTimeMillis();
		logger.info("同步过来的日初借据信息临时表数据修改借据信息表出错：[" + DateTool.formatDate(new Date(endTime), DateTool.PATTERN_DATETIME) + "]， 处理结束");
		logger.info("SERIOUS，耗时：[" + (endTime - startTime) / 1000.0 + "]秒，处理结果[" + result + "]");
		return result;
	}

	/**
	 * 根据百度同步过来的贷款每日还款文件信息数据加工初始化还款明细借据信息 <br>
	 * 0.2=1: weijj:2019年5月11日 下午5:29:49:新增 <br>
	 * 
	 * @author weijj
	 * @since 2019年5月11日 下午5:29:49
	 * @date 2019年5月11日 下午5:29:49
	 * @version 0.1
	 */
	public boolean dueData(List<TxtFileLoadBean> txtFileLoadList) {
		logger.info("同步过来的日初借据信息临时表数据修改借据表加工处理开始！");
		// 需要新增或者修改的借据信息
		List<AccLoanVO> list = new ArrayList<AccLoanVO>();
		// 处理结果
		boolean result = false;
		// 新增或者修改的数量
		int num = 0;
		// 单位转换
		final int oneHundred100 = 100;
		// 创建、修改用户
		final String createUser = "admin";
		DwBaiduLoanBean dwBaiduLoanBean = new DwBaiduLoanBean();
		// 借据信息
		AccLoanVO accLoanVO = null;
		try {
			for (int i = 0; i < txtFileLoadList.size(); i++) {
				dwBaiduLoanBean = (DwBaiduLoanBean) txtFileLoadList.get(i);
				// 借据信息
				accLoanVO = new AccLoanVO();
				accLoanVO.setBillNo(dwBaiduLoanBean.getLoanId());
				// prd_id 产品ID
				accLoanVO.setPrdId(SDicMappingUtil.getLocalSysDicVal(BdLoanConstant.PRD_CODE, dwBaiduLoanBean.getProdtp()));
				// prd_code 产品代码
				accLoanVO.setPrdCode(SDicMappingUtil.getLocalSysDicVal(BdLoanConstant.PRD_CODE, dwBaiduLoanBean.getProdtp()));
				// prd_name 产品名称
				accLoanVO.setPrdName(SDicMappingUtil.getLocalSysDicVal(BdLoanConstant.PRD_NAME, dwBaiduLoanBean.getProdtp()));
				accLoanVO.setCurType(SDicMappingUtil.getLocalSysDicVal(BdLoanConstant.CURRENCY, dwBaiduLoanBean.getCurrency()));
				accLoanVO.setLoanAmount(DueDataUtil.checkDecimalInfo(dwBaiduLoanBean.getEncashAmt(), oneHundred100));
				// prin_bal 正常本金余额
				BigDecimal prinBal = DueDataUtil.checkDecimalInfo(dwBaiduLoanBean.getPrinBal(), oneHundred100);
				// ovd_prin_bal 逾期本金余额
				BigDecimal ovdPrinBal = DueDataUtil.checkDecimalInfo(dwBaiduLoanBean.getOvdPrinBal(), oneHundred100);
				// loan_balance 借据余额 = prin_bal + ovd_prin_bal
				BigDecimal loanBalance = prinBal.add(ovdPrinBal);
				accLoanVO.setLoanBalance(loanBalance);
				accLoanVO.setLoanStartDate(DueDataUtil.dateInfoTrans(dwBaiduLoanBean.getStartDate()));
				accLoanVO.setLoanEndDate(DueDataUtil.dateInfoTrans(dwBaiduLoanBean.getEndDate()));
				accLoanVO.setReceIntCumu(DueDataUtil.checkDecimalInfo(dwBaiduLoanBean.getIntTotal(), oneHundred100));
				accLoanVO.setActualIntCumu(DueDataUtil.checkDecimalInfo(dwBaiduLoanBean.getIntRepay(), oneHundred100));
				accLoanVO.setDelayIntCumu(DueDataUtil.checkDecimalInfo(dwBaiduLoanBean.getOvdIntBal(), oneHundred100));
				// 借据逾期
				if (BdLoanConstant.LOAN_FORM_2.equals(dwBaiduLoanBean.getLoanForm())) {
					// 拖欠本金有值，正常本金为0
					// unpd_prin_bal decimal(16,2) Y 拖欠本金
					accLoanVO.setUnpdPrinBal(loanBalance);
					accLoanVO.setNormalBalance(BigDecimal.ZERO);
				} else {
					// 正常本金为有值，拖欠本金为0
					accLoanVO.setUnpdPrinBal(BigDecimal.ZERO);
					// normal_balance decimal(16,2) Y 正常贷款余额(元)
					accLoanVO.setNormalBalance(loanBalance);
				}
				accLoanVO.setOverTimesCurrent(dwBaiduLoanBean.getCurOvdTerms());
				accLoanVO.setOverTimesTotal(dwBaiduLoanBean.getTotalOvdTerms());
				accLoanVO.setLatestRepayDate(DueDataUtil.dateInfoTrans(dwBaiduLoanBean.getLastRepayDate()));
				accLoanVO.setSettlDate(DueDataUtil.dateInfoTrans(dwBaiduLoanBean.getClearDate()));
				accLoanVO.setLastUpdateTime(DateTool.getCurrentDateTime());
				if (BdLoanConstant.LOAN_FORM_2.equals(dwBaiduLoanBean.getLoanForm())) {
					// 借据逾期
					accLoanVO.setAccountStatus(LoanConstant.TZZT_YQ);
				} else {
					accLoanVO.setAccountStatus(
							SDicMappingUtil.getLocalSysDicVal(BdLoanConstant.LOAN_STATUS, dwBaiduLoanBean.getLoanStatus()));
				}
				// accLoanVO.setPrinIntRateInc(DueDataUtil.checkDecimalInfo(dwBaiduLoanTempVO.getPnltIntTotal(),
				// oneHundred100));
				// accLoanVO.setUnpdArrsIntBal(DueDataUtil.checkDecimalInfo(dwBaiduLoanTempVO.getPnltIntBal(),
				// oneHundred100));
				// unpd_arr_prn_bal decimal(16,2) Y 应收复利(应收未收) 赋值：0
				accLoanVO.setUnpdArrPrnBal(BigDecimal.ZERO);
				// act_arrs_int_bal decimal(16,2) Y 实收拖欠本金的罚息
				accLoanVO.setActArrsIntBal(DueDataUtil.checkDecimalInfo(dwBaiduLoanBean.getPnltIntRepay(), oneHundred100));
				// act_arr_prn_bal decimal(16,2) Y 实收复利 赋值：0
				accLoanVO.setActArrPrnBal(BigDecimal.ZERO);
				accLoanVO.setReturnDate(dwBaiduLoanBean.getRepayDay().toString());
				// unpd_arrs_int_bal1 decimal(16,2) Y 拖欠本金的罚息(应收未收)
				accLoanVO.setUnpdArrsIntBal1(DueDataUtil.checkDecimalInfo(dwBaiduLoanBean.getPnltIntBal(), oneHundred100));
				// unpd_arr_prn_bal1 decimal(16,2) Y 应收复利(应收未收) 赋值：0
				accLoanVO.setUnpdArrPrnBal1(BigDecimal.ZERO);
				// accLoanVO.setUnpdPrinBal(DueDataUtil.checkDecimalInfo(dwBaiduLoanTempVO.getOvdPrinBal(),
				// oneHundred100));
				accLoanVO.setIntAccr(DueDataUtil.checkDecimalInfo(dwBaiduLoanBean.getIntBal(), oneHundred100));
				accLoanVO.setDelayIntCumu1(DueDataUtil.checkDecimalInfo(dwBaiduLoanBean.getPnltIntTotal(), oneHundred100));
				accLoanVO.setPrdType(SDicMappingUtil.getLocalSysDicVal(BdLoanConstant.PRD_TYPE, dwBaiduLoanBean.getProdtp()));
				// assure_means_main char(2) Y 主担保方式 赋值：00-信用
				accLoanVO.setAssureMeansMain(BdLoanConstant.ASSURE_MEANS_MAIN_00);
				accLoanVO.setRepaymentMode(SDicMappingUtil.getLocalSysDicVal(BdLoanConstant.REPAY_MODE, dwBaiduLoanBean.getRepayMode()));
				accLoanVO.setCusType(CusTypeEnum.NATURAL_MAN.getCode());
				accLoanVO.setRepayFreq(dwBaiduLoanBean.getRepayCycle());
				accLoanVO.setCreateUser(createUser);
				accLoanVO.setCreateTime(DueDataUtil.formatDateTime10To19(dwBaiduLoanBean.getEtlDate()));
				accLoanVO.setLastUpdateUser(createUser);
				accLoanVO.setCertType(SDicCertTypeEnum.IDCARD.getValue());
				accLoanVO.setLoanUseType(BdLoanConstant.LOAN_USE_TYPE_23);
				accLoanVO.setIrAdjustMode(BdLoanConstant.IR_ADJUST_MODE_1);
				accLoanVO.setChannelCode(BdLoanConstant.BD_CHANNEL_NO);
				accLoanVO.setOverdueDays(dwBaiduLoanBean.getCurOvdDays());
				accLoanVO.setCurrTerm(dwBaiduLoanBean.getCurTerm());
				accLoanVO.setLoanTerm(dwBaiduLoanBean.getTotalTerms());
				accLoanVO.setLoadTermType(BdLoanConstant.TERM_TYPE_M);
				accLoanVO.setGraceDay(dwBaiduLoanBean.getGraceDay());
				accLoanVO.setFundFeeTotal(DueDataUtil.checkDecimalInfo(dwBaiduLoanBean.getFundFeeTotal(), oneHundred100));
				accLoanVO.setFundFeeRepay(DueDataUtil.checkDecimalInfo(dwBaiduLoanBean.getFundFeeRepay(), oneHundred100));
				accLoanVO.setChargesTotal(DueDataUtil.checkDecimalInfo(dwBaiduLoanBean.getChargesTotal(), oneHundred100));
				accLoanVO.setChargesRepay(DueDataUtil.checkDecimalInfo(dwBaiduLoanBean.getChargesRepay(), oneHundred100));
				accLoanVO.setOverdueTotal(DueDataUtil.checkDecimalInfo(dwBaiduLoanBean.getOverdueTotal(), oneHundred100));
				accLoanVO.setOverdueRepay(DueDataUtil.checkDecimalInfo(dwBaiduLoanBean.getOverdueRepay(), oneHundred100));
				accLoanVO.setRepayViolateTotal(DueDataUtil.checkDecimalInfo(dwBaiduLoanBean.getRepayViolateTotal(), oneHundred100));
				accLoanVO.setRepayViolateRepay(DueDataUtil.checkDecimalInfo(dwBaiduLoanBean.getRepayViolateRepay(), oneHundred100));
				accLoanVO.setRefundViolateTotal(DueDataUtil.checkDecimalInfo(dwBaiduLoanBean.getRefundViolateTotal(), oneHundred100));
				accLoanVO.setRefundViolateRepay(DueDataUtil.checkDecimalInfo(dwBaiduLoanBean.getRefundViolateRepay(), oneHundred100));
				accLoanVO.setServiceTotal(DueDataUtil.checkDecimalInfo(dwBaiduLoanBean.getServiceTotal(), oneHundred100));
				accLoanVO.setServiceRepay(DueDataUtil.checkDecimalInfo(dwBaiduLoanBean.getServiceRepay(), oneHundred100));
				accLoanVO.setIntReducedAmCoupon(DueDataUtil.checkDecimalInfo(dwBaiduLoanBean.getIntReducedAmCoupon(), oneHundred100));
				accLoanVO.setPnltReducedAmtCoupon(DueDataUtil.checkDecimalInfo(dwBaiduLoanBean.getPnltReducedAmtCoupon(), oneHundred100));
				accLoanVO.setFundFeeReducedAmtCoupon(
						DueDataUtil.checkDecimalInfo(dwBaiduLoanBean.getFundFeeReducedAmtCoupon(), oneHundred100));
				accLoanVO.setChargesReducedAmtCoupon(
						DueDataUtil.checkDecimalInfo(dwBaiduLoanBean.getChargesReducedAmtCoupon(), oneHundred100));
				accLoanVO.setOverdueReducedAmtCoupon(
						DueDataUtil.checkDecimalInfo(dwBaiduLoanBean.getOverdueReducedAmtCoupon(), oneHundred100));
				accLoanVO.setRepayViolateReducedAmtCoupon(
						DueDataUtil.checkDecimalInfo(dwBaiduLoanBean.getRepayViolateReduAmtCoupon(), oneHundred100));
				accLoanVO.setRefundViolateReducedAmtCoupon(
						DueDataUtil.checkDecimalInfo(dwBaiduLoanBean.getRefundViolateReduAmtCoupon(), oneHundred100));
				accLoanVO.setServiceReducedAmtCoupon(
						DueDataUtil.checkDecimalInfo(dwBaiduLoanBean.getServiceReducedAmtCoupon(), oneHundred100));
				accLoanVO.setPrinReducedAmtManual(DueDataUtil.checkDecimalInfo(dwBaiduLoanBean.getPrinReducedAmtManual(), oneHundred100));
				accLoanVO.setIntReducedAmtManual(DueDataUtil.checkDecimalInfo(dwBaiduLoanBean.getIntReducedAmtManual(), oneHundred100));
				accLoanVO.setPnltReducedAmtManual(DueDataUtil.checkDecimalInfo(dwBaiduLoanBean.getPnltReducedAmtManual(), oneHundred100));
				accLoanVO.setFundFeeReducedAmtManual(
						DueDataUtil.checkDecimalInfo(dwBaiduLoanBean.getFundFeeReducedAmtManual(), oneHundred100));
				accLoanVO.setChargesReducedAmtManual(
						DueDataUtil.checkDecimalInfo(dwBaiduLoanBean.getChargesReducedAmtManual(), oneHundred100));
				accLoanVO.setOverdueReducedAmtManual(
						DueDataUtil.checkDecimalInfo(dwBaiduLoanBean.getOverdueReducedAmtManual(), oneHundred100));
				accLoanVO.setRepayViolateReducedAmtManual(
						DueDataUtil.checkDecimalInfo(dwBaiduLoanBean.getRepayViolateReduAmtManual(), oneHundred100));
				accLoanVO.setRefundViolateReducedAmtManual(
						DueDataUtil.checkDecimalInfo(dwBaiduLoanBean.getRefundViolateReduAmtManual(), oneHundred100));
				accLoanVO.setServiceReducedAmtManual(
						DueDataUtil.checkDecimalInfo(dwBaiduLoanBean.getServiceReducedAmtManual(), oneHundred100));
				list.add(accLoanVO);
			}
			if (list != null && !list.isEmpty()) {
				num = accLoanService.insertOrUpdateAccLoan(list);
			}
			String num_msg = "【借据信息表】插入或更新数据处理结果:" + num;
			logger.info(num_msg, "message{}");
			if (num > 0) {
				result = true;
			}
		} catch (Exception e) {
			e.printStackTrace();
			String tableName = "acc_loan";
			String errorMsg = "同步过来的日初借据信息临时表数据修改借据信息表出错";
			String remark = "同步过来的日初借据信息临时表数据修改借据信息表出错，错误信息：" + e.getMessage();
			addErrorInfo(tableName, MonAlrmLvlEnum.SERIOUS.getEnname(), errorMsg, remark);
			logger.error(remark);
		} finally {
			// 清空信息
			list = null;
			txtFileLoadList = null;
		}
		logger.info("同步过来的日初借据信息临时表数据修改借据表加工处理结束！");
		return result;
	}

	/**
	 * 
	 * 记录异常信息 <br>
	 * 0.1:weijj:2019年5月7日 上午11:31:23:新增 <br>
	 * 
	 * @author weijj
	 * @since 2019年5月7日 上午11:31:23
	 * @date 2019年5月7日 上午11:31:23
	 * @version 0.1
	 */
	private void addErrorInfo(String tableName, String errorType, String errorMsg, String remark) {
		AccoutErroTempVO accoutErroTempVO = new AccoutErroTempVO();
		// 表名
		accoutErroTempVO.setTableName(tableName);
		// 错误级别
		accoutErroTempVO.setErroType(errorType);
		// 错误信息
		accoutErroTempVO.setErroMsg(errorMsg);
		// 备注
		accoutErroTempVO.setRemark(remark);
		// 创建时间
		accoutErroTempVO.setCreateData(DateTool.getCurrentDateTime());
		// 修改时间
		accoutErroTempVO.setLastModifyTime(DateTool.getCurrentDateTime());
		// 记录异常信息
		accoutErroTempService.insert(accoutErroTempVO);
	}
}
